package yxy.apple.util;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 数学工具类
 */
public class MathUtil {
	//相除
	public static String str_divide (String v1, String v2, Integer scale) {
        if (v1 == null || v2 == null || "0".equals(v1) || "0.0".equals(v1) || "0".equals(v2) || "0.0".equals(v2) || "0.00".equals(v2)) {
            return "0";
        }
        BigDecimal res = new BigDecimal(v1).divide(new BigDecimal(v2), scale, RoundingMode.HALF_UP);
        return String.valueOf(res);
    }

    //减
    public static String str_subtract (String v1, String v2) {
        BigDecimal res = new BigDecimal(v1).subtract(new BigDecimal(v2));
        return String.valueOf(res);
    }

    //乘
    public static String str_multiply (String v1, String v2) {
        BigDecimal res = new BigDecimal(v1).multiply(new BigDecimal(v2));
        return String.valueOf(res);
    }

	//乘
	public static String str_multiply (String v1, String v2, Integer scale) {
		BigDecimal res = new BigDecimal(v1).multiply(new BigDecimal(v2));
		return String.valueOf(res.setScale(scale, RoundingMode.HALF_UP));
	}

    //加
    public static String str_add (String v1, String v2) {
        BigDecimal res = new BigDecimal(v1).add(new BigDecimal(v2));
        return String.valueOf(res);
    }

	public static void main(String[] args) {
		//
	}

}
